package com.its.common.net.client.test;

import cn.hutool.core.util.RandomUtil;
import com.its.common.net.client.handler.BaseUdpClientHandler;
import com.its.common.net.core.dto.GenericNetDTO;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.socket.DatagramPacket;
import lombok.extern.slf4j.Slf4j;

/**
 * @Author xiaxp
 * @Date 9/14/22 13:08
 * @Description
 */
@Slf4j
public class CustomUdpClientTestHandler extends BaseUdpClientHandler {
//    @Override
//    protected void handleAfterRead(ChannelHandlerContext ctx, GenericNetDTO data) {
//        log.info("数据处理成功后的操作..............");
//    }

    @Override
    public void handleData(ChannelHandlerContext ctx, GenericNetDTO<DatagramPacket> data) {
        //TODO 模拟处理时间
        try {
            Thread.sleep(RandomUtil.randomLong(100, 1500));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        DatagramPacket packet = data.getData();
        byte[] bytes = extract2bytes(packet);

//        log.error("客户端接受的消息 : " + HexUtil.encodeHexStr(bytes));
    }
}
